package modulesAPI.v2.composite;

import java.util.GregorianCalendar;

import modulesAPI.v2.Module;
import modulesAPI.v2.ViewType;
import person.Guest;

import com.caterina.components.CPanel;
import com.caterina.resources.CModules;

import event.Event;
import event.Event.EventType;
import event.Event.PreparationType;

public class MGuest extends Module<Guest> {
	/**
	 * Crea un nuovo modulo per l'inserimento/rappresentazione di un ospite
	 * */
	public MGuest(Module<?> ownerModule, Guest content, String tag,String description, ViewType viewType,int...options) {
		super(ownerModule, content, tag, description, viewType,options);
		createModules();
		this.addModules(person, event);
	}
	/**
	 * Crea un nuovo modulo per l'inserimento/rappresentazione di un ospite
	 * */
	public MGuest(Module<?> ownerModule, String tag,String description, ViewType viewType) {
		this(ownerModule, 
				new Guest("", "", "", "", "", "", "", 
				new Event("", EventType.BIRTHDAY, PreparationType.STANDARD,Event.ServiceType.TABLE, new GregorianCalendar(), new GregorianCalendar(), "", 0)), 
				tag, description, viewType);
	}
	private void createModules(){
		this.person=new MPerson(this, this.getContent(), "GUEST_DETAILS", "GUEST_DETAIL_DESC", this.getViewType());
		this.event=new MEvent(this, this.getContent().getEvent(), "OCCURENCE", "OCCURENCE_DESC", this.getViewType());
	}
	@Override
	protected CPanel getReadOnlyPanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	@Override
	protected CPanel getWritablePanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	@Override
	public CPanel getInListPanel(boolean isSelected) {
		return CModules.formatForList(this.getContent().getName()+"  "+this.getContent().getSurname(), 
				this.getContent().getEvent().getEventName(), isSelected);
	}
	@Override
	protected CPanel getOneLinePanel(boolean isSelected) {
		return null;
	}
	protected void beforeFireChange(){
		this.setContent(new Guest(
				this.getContent().getId(), 
				person.getContent(),
				event.getContent()
				));
	}
	@Override
	protected void beforeFireChange(Module<?> mod) {
		
	}
	@Override
	protected void afterFireChange(Module<?> mod) {
		
	}
	private MPerson person;
	private MEvent event;
	
}
